﻿@using hc.epm.ViewModel;
@model MonitorView
@{
    ViewBag.Title = "确认检查";
}
<style>
    .datalist tr td {
        padding: 2px;
    }

        .datalist tr td input[type="text"] {
            width: 100%;
            height: 100%;
            border: 1px solid #ccc;
            padding: 0 10px;
            box-sizing: border-box;
        }

    .selectpicker {
        width: 100%;
        height: 100%;
    }
</style>
<body>
    <div class="contentData">
        <div class="tab-view">
            <form id="mainForm">
                <div class="tab">
                    <div class="long-text">
                        <label for="PrejectName"><span class="star">*</span>&nbsp;项目名称&nbsp;:</label>
                        <input type="text" id="ProjectName" name="ProjectName" value="@Model.Monitor.ProjectName" disabled autocomplete="off" />
                        <i class="pic iconfont" width="20" height="30" style="cursor:pointer; left:596px;">&#xe76a;</i>
                        <input type="hidden" name="projectId" id="projectId" value="@Model.Monitor.ProjectId" />
                    </div>
                    <div class="long-text">
                        <label for="Title"><span class="star">*</span>&nbsp;检查标题&nbsp;:</label>
                        <input type="text" id="Title" name="Title" disabled value="@Model.Monitor.Title" />
                    </div>
                    <div class="intro" style="height:100%;">
                        <div><label>&nbsp;问题&nbsp;:</label></div>
                        <table class="datalist" style="word-break:break-all;word-wrap:break-word;width:88%">
                            <thead>
                                <tr>
                                    <th width="30%">问题</th>
                                    <th width="25%">整改单位</th>
                                    <th width="30%">要求完成日期</th>
                                </tr>
                            </thead>
                            <tbody>
                                @if (Model.MonitorDetails != null && Model.MonitorDetails.Count() > 0)
                                {
                                    foreach (var item in Model.MonitorDetails)
                                    {
                                        <tr>
                                            <td>@item.Name</td>
                                            <td>@item.RectifCompanyName</td>
                                            <td>
                                                @(item.Deadline == null ? "" : Convert.ToDateTime(item.Deadline).ToString("yyyy-MM-dd"))
                                            </td>
                                        </tr>
                                    }
                                }
                            </tbody>
                        </table>
                    </div>
                    <input type="hidden" name="Id" id="Id"  value="@Model.MonitorRectifRecord.Id" />
                    <div class="short-text">
                        <label><span class="star">*</span>&nbsp;整改完成时间&nbsp;:</label>
                        <input type="text" id="FinishDate" name="FinishDate" disabled onClick="WdatePicker({ el: 'FinishDate' })" autocomplete="off" value="@(Model.MonitorRectifRecord.FinishDate == null ? "" : Convert.ToDateTime(Model.MonitorRectifRecord.FinishDate).ToString("yyyy-MM-dd"))">
                        <i onClick="WdatePicker({ el: 'FinishDate' })" class="pic iconfont" width="20" height="30" style="cursor:pointer;">&#xe7e2;</i>
                    </div>
                    <div class="intro">
                        <div><label><span class="star">*</span>&nbsp;整改内容&nbsp;:</label></div>
                        <div>
                            <textarea class="sub-description" value="" id="Content" name="Content" disabled>@Model.MonitorRectifRecord.Content</textarea>
                        </div>
                    </div>
                    <div class="upload" style="margin-bottom:0px;">
                        <div><label>&nbsp;附件上传&nbsp;:</label></div>
                        <div class="btn-upload">
                            <input type="button" id="btnUploadFile" style="position: relative; z-index: 1;" value="上传附件" />
                            <input type="file" id="loadFile" name="loadFile" style="display:none" onchange="uploadFile()">
                        </div>
                    </div>
                    <div style="width:100%;" id="fileListFile" class="fileListFile">
                        <ul class="fileShow"></ul>
                        <input type="hidden" name="fileDataJsonFile" id="fileDataJsonFile">
                    </div>
                    <div class="long-text">
                        <label for="Result">&nbsp;检查结果&nbsp;:</label>
                        <input type="radio" name="Result" value="95" checked />检查通过
                        <input type="radio" name="Result" value="99" />检查不通过
                    </div>
                    <div class="intro suggest" style="display:none">
                        <div><label>&nbsp;整改建议&nbsp;:</label></div>
                        <div>
                            <textarea class="sub-description" id="Remark" name="Remark" ></textarea>
                        </div>
                    </div>
                </div>
                <div class="button-group btn-center">
                    <button type="button" class="saveBut">保存</button>
                    <input type="hidden" name="State" id="State" />
                </div>
            </form>
        </div>
    </div>
    <script>
        var fileDataArray = [];
        function uploadFile() {
            if (document.getElementById("loadFile").files.length == 0) {
                return;
            }
            var fileObj = document.getElementById("loadFile").files[0]; // js 获取文件对象
            var formFile = new FormData();
            formFile.append("file", fileObj);
            var path = formFile;

            $.ajax({
                url: "/Upload/UploadHB",
                type: "POST",
                data: path,
                contentType: false,
                processData: false,
                success: function (data) {
                    for (var i = 0; i < data.length; i++) {
                        var obj = {};
                        obj.Name = data[i].Name;
                        obj.GuidId = data[i].GuidId;
                        obj.Size = data[i].Size;
                        obj.ImageType = data[i].ImageType;
                        obj.Group = data[i].ResponseObject.FDFS_GROUP;
                        obj.Url = data[i].ResponseObject.FDFS_NAME;
                        fileDataArray.push(obj);

                        if (data[i].ImageType == null) {
                            var imgUrl = getFileImg(obj.Name);
                            var odiv = '<li id="' + obj.GuidId + '">';
                            odiv += '<div><img src="' + imgUrl + '" style="width: 20px;height: 20px;cursor: pointer;" class="imgShow"/><a href="javascript:;" target="_blank">' + obj.Name + '</a></div>';
                            odiv += '<div style="text-align:right; width:80px;">' + obj.Size + '</div>';
                            odiv += '<span style="margin-left:20px;">' + data[i].UploadName + '</span>';
                            odiv += '<span style="margin-left:20px;">' + new Date(formatDateByJson(data[i].UploadDate)).Format("yyyy-MM-dd") + '</span>';
                            odiv += '<span style="margin-left:20px;cursor: pointer;color:blue" class="fileDel" data-val="' + obj.GuidId + '">删除</span>'
                            odiv += '</li>';
                            $('#fileListFile .fileShow').append(odiv);
                        }
                    }
                    fileDataJson = JSON.stringify(fileDataArray);
                    $("#fileDataJsonFile").val(fileDataJson);
                    $("#loadFile").val("");
                }
            });
        }

        $(function () {
            $('#btnUploadFile').click(function () {
                document.getElementById("loadFile").click();
            });
        });
        $(":radio").click(function () {
            var result = $(this).val();
            if (result == "99") {
                $(".suggest").show();
            } else {
                $(".suggest").hide();
            }
        });
        layui.use(['layer', 'form', 'element'], function () {
            var layer = layui.layer, element = layui.element, $ = layui.jquery;
           
            //删除附件
            $("#fileListFile").on("click", ".fileDel", function () {
                $(this).parents("li").remove();
                var toremove = '';
                var id = $(this).data("val");
                //----删除初始文件对应的值
                fileDataArray = fileDataArray.filter(function (item, index, arr) {
                    return item.GuidId != id
                })
                fileDataJsonFile = JSON.stringify(fileDataArray);
                $("#fileDataJsonFile").val(fileDataJsonFile);
            });
            //确认
            $(".saveBut").click(function () {
                if ($("#mainForm").valid()) {
                    //var search = $("form").serialize();
                    var id = $("#Id").val();
                    var state = $("input[type=radio]:checked").val();
                    var remark = $("#Remark").val();
                    $.post("ConfirmRectifyResult", { id: id, state: state, Remark: remark }, function (data) {
                        if (data.Flag) {
                            layer.msg("操作成功", { time: 1000, icon: 1 }, function () {
                                window.location.href = "/Monitor/IndexAQ";
                            });
                        } else {
                            layer.alert(data.Message, { icon: 2 });
                        }
                    });
                }
            });
        });
    </script>
</body>
